<template>
  <div class="app-container">
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <el-menu
          :default-active="route.path"
          class="sidebar-menu"
          :collapse="isCollapse"
          background-color="#304156"
          text-color="#bfcbd9"
          active-text-color="#409EFF"
          router
        >
          <el-menu-item index="/">
            <el-icon><Document /></el-icon>
            <span>图书列表</span>
          </el-menu-item>
          <el-menu-item index="/borrows">
            <el-icon><List /></el-icon>
            <span>借阅管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="header-left">
            <el-icon class="menu-icon" @click="isCollapse = !isCollapse">
              <Fold v-if="!isCollapse"/>
              <Expand v-else/>
            </el-icon>
            <h2>图书管理系统</h2>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { Document, List, Fold, Expand } from '@element-plus/icons-vue'

const route = useRoute()
const isCollapse = ref(false)
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

.app-container {
  height: 100vh;
}

.el-container {
  height: 100%;
}

.el-aside {
  background-color: #304156;
  transition: width 0.3s;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #dcdfe6;
  padding: 0 20px;
  display: flex;
  align-items: center;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.menu-icon {
  font-size: 20px;
  cursor: pointer;
}

.menu-icon:hover {
  color: var(--el-color-primary);
}

.sidebar-menu {
  height: 100%;
  border-right: none;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
}

h2 {
  margin: 0;
  font-size: 18px;
  color: #303133;
}
</style>
